﻿#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
#include <string>

using namespace std;

//找一个二维字符数组中是否有某个字符串存在
//bool path[101][101] = { false };
//int dx[4] = { 0,0,-1,1};
//int dy[4] = { -1,1,0,0 };
//
//bool dfs(string& s, vector<string>& vs, int i, int j, int pos)
//{
//	if (pos == s.size() - 1)
//	{
//		return true;
//	}
//
//	path[i][j] = true;
//	
//	for (int index = 0; index < 4; index++)
//	{
//		int x = i + dx[index];
//		int y = j + dy[index];
//
//		if (x >= 0 && x < vs.size() && y >= 0 && y < vs[0].size() && !path[x][y] && vs[x][y] == s[pos + 1])
//		{
//			if (dfs(s, vs, x, y, pos + 1)) return true;
//		}
//	}
//
//	path[i][j] = false;
//
//	return false;
//}
//
//int main()
//{
//	vector<string> vs = { "XYZE","SFZS","XDEE" };
//	string s = "XYF";
//
//	for (int i = 0; i < vs.size(); i++)
//	{
//		for (int j = 0; j < vs[0].size(); j++)
//		{
//			if (vs[i][j] == s[0])
//			{
//				if (dfs(s, vs, i, j, 0))
//				{
//					cout << "FIND!" << endl;
//					return 0;
//				}
//			}
//		}
//	}
//
//	cout << "FAIL!" << endl;
//
//	return 0;
//}

class Solution
{
	int m, n;
	bool vis[101][101] = { 0 };
	int dx[4] = { 0, 0, 1, -1 };
	int dy[4] = { 1, -1, 0, 0 };
public:
	bool exist(vector<string>& board, string word)
	{
		m = board.size(), n = board[0].size();
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (board[i][j] == word[0])
				{
					if (dfs(board, i, j, word, 0)) return true;
				}
			}
		}
		return false;
	}

	bool dfs(vector<string>& board, int i, int j, string& word, int pos)
	{
		if (pos == word.size() - 1)
		{
			return true;
		}
		vis[i][j] = true;
		for (int k = 0; k < 4; k++)
		{
			int a = i + dx[k], b = j + dy[k];
			if (a >= 0 && a < m && b >= 0 && b < n && !vis[a][b] && board[a][b]
				== word[pos + 1])
			{
				if (dfs(board, a, b, word, pos + 1)) return true;
			}
		}
		vis[i][j] = false;
		return false;
	}
};

//苹果
class Solution
{
	int m, n;
	int dx[4] = { 0, 0, 1, -1 };
	int dy[4] = { 1, -1, 0, 0 };
	bool vis[1010][1010] = { 0 };
public:
	int rotApple(vector<vector<int> >& grid)
	{
		m = grid.size(), n = grid[0].size();
		queue<pair<int, int>> q;
		for (int i = 0; i < m; i++)
			for (int j = 0; j < n; j++)
				if (grid[i][j] == 2)
					q.push({ i, j });
		int ret = 0;
		while (q.size())
		{
			int sz = q.size();
			ret++;
			while (sz--)
			{
				auto [a, b] = q.front();
				q.pop();
				for (int i = 0; i < 4; i++)
				{
					int x = a + dx[i], y = b + dy[i];
					if (x >= 0 && x < m && y >= 0 && y < n && grid[x][y] == 1
						&& !vis[x][y])
					{
						vis[x][y] = true;
						q.push({ x, y });
					}
				}
			}
		}
		for (int i = 0; i < m; i++)
			for (int j = 0; j < n; j++)
				if (grid[i][j] == 1 && !vis[i][j])
					return -1;
		return ret - 1;
	}
}

#include <iostream>
#include <string>
using namespace std;
int t, n, k;
string s;
int fun()
{
	int ret = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'L')
		{
			ret--;
		}
		else
		{
			if (i - 1 >= 0 && i - 2 >= 0 && s[i - 1] == 'W' && s[i - 2] == 'W')
			{
				ret += k;
			}
			else
			{
				ret += 1;
			}
		}
	}
	return ret;
}
int main()
{
	cin >> t;
	while (t--)
	{
		cin >> n >> k >> s;
		cout << fun() << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <string>
using namespace std;
string s;
bool isprim(int n) // 判断 n 是否是质数
{
	1 2 3 4 5 6 7 8 9
		10
		比特就业课if(n < 2) return false;
	for (int i = 2; i <= sqrt(n); i++)
	{
		if (n % i == 0) return false;
	}
	return true;
}
int main()
{
	cin >> s;
	int hash[26] = { 0 };
	for (auto ch : s)
	{
		hash[ch - 'a']++;
	}
	int minn = 1000, maxn = 0;
	for (int i = 0; i < 26; i++)
	{
		if (hash[i])
		{
			minn = min(minn, hash[i]);
			maxn = max(maxn, hash[i]);
		}
	}
	if (isprim(maxn - minn))
	{
		cout << "Lucky Word" << endl;
		cout << maxn - minn << endl;
	}
	else
	{
		cout << "No Answer" << endl;
		cout << 0 << endl;
	}
	return 0;
}


class Solution
{
public:
	int solve(vector<vector<char>>& grid)
	{
		int ret = 0; // 记录最终结果
		int m = grid.size(), n = grid[0].size();
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (grid[i][j] == '1')
				{
					ret++; // 发现⼀个岛屿
					dfs(grid, i, j); // 把这个岛屿全部修改成 '0'
				}
			}
		}
		return ret;
	}
	int dx[4] = { 0, 1, -1, 0 };
	int dy[4] = { 1, 0, 0, -1 };
	void dfs(vector<vector<char>>& grid, int i, int j)
	{
		grid[i][j] = '0'; // 把该位置先变成 '0'
		int m = grid.size(), n = grid[0].size();
		// 遍历相邻的所有位置
		for (int k = 0; k < 4; k++)
		{
			int x = i + dx[k], y = j + dy[k];
			if (x >= 0 && x < m && y >= 0 && y < n && grid[x][y] == '1')
				dfs(grid, x, y);
		}
	}
};


#include <iostream>
#include <algorithm>
using namespace std;
int t;
int arr[6];
int main()
{
	cin >> t;
	while (t--)
	{
		for (int i = 0; i < 6; i++) cin >> arr[i];
		sort(arr, arr + 6);
		if (arr[0] + arr[1] > arr[2] && arr[3] + arr[4] > arr[5] ||
			arr[0] + arr[2] > arr[3] && arr[1] + arr[4] > arr[5] ||
			arr[0] + arr[3] > arr[4] && arr[1] + arr[2] > arr[5] ||
			arr[0] + arr[4] > arr[5] && arr[1] + arr[2] > arr[3]){
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
	return 0;
}